{extend name="public:layout" /}

{block name="title"}
    <title>{:site('siteName')}-充值记录</title>
{/block}

{block name="css"}
    <style>
        .layui-btn{    height: 25px;line-height: 25px;    padding: 0 3px;}
        .layui-form-item .layui-input-inline{    margin: 0 0 10px 0px;}
        .sell-tab { height: 40px; border-bottom: 1px solid #e2e2e2 }
        .sell-tab li { width: 50%; float: left; text-align: center; line-height: 40px; }
        .sell-tab .this { color: #009688; border-bottom: 3px solid #5FB878; margin-bottom: -3px;}
    </style>
{/block}

{block name="content"}
    <ul class="sell-tab">
        <li><a href="{:url('index/agent/index')}">代理列表</a></li>
        <li class="this">充值记录</li>
    </ul>
    <div class="account_li">
        <ul>
            {volist name="recharges" id="v"}
                <li class="tips" data-msg="姓名：{$v.realname}<br>手机：{$v.mobile}<br>QQ：{$v.qq}<br>开户行：{$v.bank}<br>卡号：{$v.bank_card}">
                    <p><span>代理信息</span><br />{$v.username}</p>
                    <p><span>数量</span><br />{$v.num}</p>
                    <p>
                        <span>状态</span><br />
                        {eq name="v.status" value="-1"}充值失败{/eq}
                        {eq name="v.status" value="0"}待支付{/eq}
                        {eq name="v.status" value="1"}已支付{/eq}
                        {eq name="v.status" value="2"}充值成功{/eq}
                    </p>
                    <p><span>说明</span> <br />{$v.explain}</p>
                    <p><span>时间</span><br />{:date('m-d H:i',$v['create_time'])}</p>
                    <p>
                        <span>操作</span><br />
                        {if $v['status'] == 0}
                            <button data-rid="{$v.id}" class="layui-btn layui-btn-mini layui-btn-main confirm-pay">已支付</button>
                            <button data-rid="{$v.id}" class="layui-btn layui-btn-mini layui-btn-danger confirm-close">取消</button>
                        {/if}
                    </p>
                </li>
            {/volist}
        </ul>
    </div>
    <div class="page">
        {$recharges->render()}
    </div>
{/block}

{block name="script"}
    <script type="text/javascript">
        layui.use(['form', 'layer'], function(){
            var $ = layui.jquery;
            var layer = layui.layer;

            $('.tips').click(function() {
                var tips = $(this).data('msg');
                layer.open({
                    title: "",content: tips
                }); 
            });

            $('.confirm-pay').click(function() {
                var rid = $(this).data('rid');
                checkPwd(function(pwd){
                    layer.confirm('确认已经支付。', {
                        btn: ['确认', '取消'],
                        icon: 3
                    }, function(index) {
                        $.post('{:url("index/agent/record")}', {id: rid,status:'1',pwd:pwd}, function(res) {
                            if(res.status == 1){
                                layer.msg(res.msg, {
                                    time: 1000
                                }, function() {
                                    location.reload();
                                });
                            }else{
                                layer.msg(res.msg);
                            }
                        },'json');
                        layer.close(index);
                    });
                });
                return false;
            });

            $('.confirm-close').click(function() {
                var rid = $(this).data('rid');
                checkPwd(function(pwd){
                    layer.confirm('确认取消充值。', {
                        btn: ['确认', '取消'],
                        icon: 3
                    }, function(index) {
                        $.post('{:url("index/agent/record")}', {id: rid,status:'-1',pwd:pwd}, function(res) {
                            if(res.status == 1){
                                layer.msg(res.msg, {
                                    time: 1000
                                }, function() {
                                    location.reload();
                                });
                            }else{
                                layer.msg(res.msg);
                            }
                        },'json');
                        layer.close(index);
                    });
                });
                
                return false;
            });
            
        });
    </script>
{/block}